/*
 * ============================================================================
 *                   GNU Lesser General Public License
 * ============================================================================
 *
 *
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 *
 *
 */

package rad.framework.search.directory;

import java.io.IOException;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockFactory;
/**
 * Acts as a proxy for the Directory that will default to the ManagedDirectory.instance if
 * not directory is set.
 * 
 * @author boudyacho
 * */
public class DirectoryProxy extends Directory {

	private Directory delegate;

	/**
	 * Returns the set delegate if it exists, otherwise it will return 
	 * an instance of {@link ManagedDirectory}.
	 * @return set directory or managedDirectory.instance
	 * */
	private Directory getDelegate() {
		if (delegate == null) {
			delegate = ManagedDirectory.instance();
		}
		return delegate;
	}
	
	public void clearLock(String name) throws IOException {
		getDelegate().clearLock(name);
	}

	public void close() throws IOException {
		getDelegate().close();
	}

	public IndexOutput createOutput(String arg0) throws IOException {
		return getDelegate().createOutput(arg0);
	}

	public void deleteFile(String arg0) throws IOException {
		getDelegate().deleteFile(arg0);
	}

	public boolean fileExists(String arg0) throws IOException {
		return getDelegate().fileExists(arg0);
	}

	public long fileLength(String arg0) throws IOException {
		return getDelegate().fileLength(arg0);
	}

	public long fileModified(String arg0) throws IOException {
		return getDelegate().fileModified(arg0);
	}

	public LockFactory getLockFactory() {
		return getDelegate().getLockFactory();
	}

	public String getLockID() {
		return getDelegate().getLockID();
	}

	public String[] list() throws IOException {
		return getDelegate().list();
	}

	public Lock makeLock(String name) {
		return getDelegate().makeLock(name);
	}

	public IndexInput openInput(String name, int bufferSize) throws IOException {
		return getDelegate().openInput(name, bufferSize);
	}

	public IndexInput openInput(String arg0) throws IOException {
		return getDelegate().openInput(arg0);
	}

	public void renameFile(String arg0, String arg1) throws IOException {
		getDelegate().renameFile(arg0, arg1);
	}

	public void setLockFactory(LockFactory lockFactory) {
		getDelegate().setLockFactory(lockFactory);
	}

	public void sync(String name) throws IOException {
		getDelegate().sync(name);
	}

	public void touchFile(String arg0) throws IOException {
		getDelegate().touchFile(arg0);
	}
	
	
}